﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WorkFlowBLL;

namespace QLCF.Forms.admin
{
    public partial class popupEditAdmin : Form
    {
        private int adminId = -1;
        public popupEditAdmin()
        {
            InitializeComponent();
        }
        frmListAdmin frmlstAdmin = null;        
        public popupEditAdmin(frmListAdmin frmA1, int m_adminId)
        {
            InitializeComponent();
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            dateTimePicker1.CustomFormat = "dd/MM/yyyy";
            frmlstAdmin = frmA1;
            adminId = m_adminId;
            CtrAdmin ctra = new CtrAdmin();
            var info=ctra.GetInfoAdminByAdminID(adminId);
            lblUserName.Text = info.UserName;
            txtFullName.Text = info.FullName;
            dateTimePicker1.Value = info.Birthday??DateTime.Now;
            txtEmail.Text = info.Email;
            txtPhone.Text = info.Phone;
            txtDes.Text = info.Description;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            CtrAdmin ctra= new CtrAdmin();
            if (ctra.UpdateAdminInfo(adminId, txtFullName.Text, dateTimePicker1.Value, txtEmail.Text, txtPhone.Text, txtDes.Text) > 0)
            {
                ctra.LogInsert(Program.UserEntity.UserID,Program.UserEntity.UserName, 2, "Sửa thông tin người dùng \"" + lblUserName.Text + "\"","Quản lý người dùng");
                frmlstAdmin.LoadAdmin();
                this.Close();
            }
            else
                MessageBox.Show("Lỗi sửa người dùng!", "Thông báo");
        }
    }
}
